@extends('manage._layout')

@section('page-title')
    修改用户
@stop
@section('page-breadcrumbs')
    <li>
        <a href="{{route('user_list')}}" title="">
            用户管理
        </a>
    </li>
    <li class="current">
        <a href="javascript:;" title="">
            修改
        </a>
    </li>
@stop
@section('page-buttons')
    <li>
        <a href="{{route('user_list')}}" title="">
            <i class="icon-reply"></i>
            <span>返回</span>
        </a>
    </li>
@stop
@section('page-content')
    <form class="form-horizontal" role="form" action="" enctype="multipart/form-data">
        <div class="form-group">
            <label for="name" class="col-sm-2 control-label">用户名</label>
            <div class="col-sm-5">
                <input type="text" class="form-control" name="name" id="name"
                   value="{{$userData->name}}"    placeholder="请输入用户名">
            </div>
        </div>


        <div class="form-group">
            <label for="name" class="col-sm-2 control-label">密码</label>
            <div class="col-sm-5">
                <input type="text" class="form-control" name="pass" id="pass"
                       value=""  placeholder="请输入密码">
            </div>
        </div>


        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="button" class="btn btn-default" id="sub">添加</button>
            </div>
        </div>
        <input type="hidden" value="{{$userData->uid}}" id="uid">
    </form>
    <script>
        $(document).ready(function () {
            $('#sub').click(function () {
                if ($('#name').val() == '') {
                    layer.alert('请填写用户名称');
                    return false;
                }

                var postdata = {
                    name: $('#name').val(),
                    pass: $('#pass').val(),
                    uid : $('#uid').val(),
                };

                $.ajax({
                    type: 'POST',
                    url: '{{URL::route('user_edit_post')}}',
                    headers: { 'X-CSRF-TOKEN' : '{{ csrf_token() }}' },
                    data: postdata,
                    success: function (res) {
                        if (res.error == 0) {
                            location.href = '{{URL::route('user_list')}}';
                        } else {
                            layer.alert(res.message);
                        }
                    },
                    error: function(XMLHttpRequest) {
                        if(XMLHttpRequest.status==403){
                            layer.alert(noAccessMsg);
                        }else{
                            layer.alert(otherErrorMsg);
                        }
                    }
                });
            });

        });
    </script>
@stop